import javax.swing.*;

public class Maze extends JPanel {
    private  int NUM;
    private int width;
    private int padding; // NUM：迷宫大小；width：每个格子的宽度和高度
    private static Lattice[][] maze;
    private int ballX, ballY; // 球的位置，在第几行第几列格子上
    private boolean drawPath = false; // flag，标识是否画出路径

    public int getNUM() {
        return NUM;
    }

    public void setNUM(int NUM) {
        this.NUM = NUM;
    }

    @Override
    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getPadding() {
        return padding;
    }

    public void setPadding(int padding) {
        this.padding = padding;
    }

    public  static Lattice[][] getMaze() {
        return maze;
    }

    public static void setMaze(Lattice[][] maze) {
        Maze.maze = maze;
    }

    public int getBallX() {
        return ballX;
    }

    public void setBallX(int ballX) {
        this.ballX = ballX;
    }

    public int getBallY() {
        return ballY;
    }

    public void setBallY(int ballY) {
        this.ballY = ballY;
    }

    public boolean isDrawPath() {
        return drawPath;
    }

    public void setDrawPath(boolean drawPath) {
        this.drawPath = drawPath;
    }

    Maze(int m, int wi, int p) {
        NUM = m;
        width = wi;
        padding = p;
        maze = new Lattice[NUM][NUM];
        for (int i = 0; i < NUM; i++) {
            for (int j = 0; j < NUM; j++) {
                maze[i][j] = new Lattice(i, j);
            }
        }
        createMaze();
        setKeyListener();
        this.setFocusable(true);
    }

    // 初始化游戏，重开一局时使用
    private void init() {
        for (int i = 0; i <= NUM - 1; i++) {
            for (int j = 0; j <= NUM - 1; j++) {
                maze[i][j].setFather(null);
                maze[i][j].setFlag(Lattice.NOTINTREE);
            }
        }
        ballX = 0;
        ballY = 0;
        drawPath = false;
        CreateMaze.createMaze();
        this.setFocusable(true);
        repaint();
    }
}